/*
 * @Author: 陈德基
 * @Date: 2021-06-10 16:33:21
 * @LastEditTime: 2021-11-16 21:56:51
 * @Description: 
 * @FilePath: \copy_gsy_github_app_flutter\lib\page\main\widgets\base_index_with_pages_state.dart
 * 联系方式：
 * wx: melody_2009
 * qq: 7815171323 
 */
import 'package:flutter/material.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'base_index_page.dart';
import 'lazy_index_stack_widget.dart';

typedef ItemClickCallback = void Function(int);

abstract class BaseIndexPageWithChildPagesWidget extends BaseIndexPageWidget {
  BaseIndexPageWithChildPagesWidget({
    this.appBar,
    this.bottomNavigationBarBackgroudColor,
    this.selectedLabelStyle,
    this.unSelectedLabelStyle,
    this.callback,
  }) : super();

  Color? bottomNavigationBarBackgroudColor;
  TextStyle? selectedLabelStyle;
  TextStyle? unSelectedLabelStyle;
  PreferredSizeWidget? appBar;

  ItemClickCallback? callback;

  @override
  Widget buildIndexPage() {
    return Scaffold(
      appBar: appBar,
      bottomNavigationBar: Obx(() => Container(
            decoration: BoxDecoration(boxShadow: [
              BoxShadow(
                  color: Colors.black12,
                  offset: Offset(0.0, -10),
                  blurRadius: 20)
            ]),
            child: BottomNavigationBar(
              onTap: (i) {
                controller.state.updatePagePosition(i);
                callback?.call(i);
              },
              type: BottomNavigationBarType.fixed,
              items: barItems(),
              backgroundColor:
                  bottomNavigationBarBackgroudColor ?? Colors.white,
              selectedLabelStyle: selectedLabelStyle ??
                  TextStyle(
                      color: Color.fromARGB(255, 30, 28, 29), fontSize: 20),
              unselectedLabelStyle: unSelectedLabelStyle ??
                  TextStyle(
                      color: Color.fromARGB(255, 103, 103, 103), fontSize: 20),
              currentIndex: controller.state.position,
            ),
          )),
      body: Obx(() => LazyIndexedStack(
          index: controller.state.position,
          reuse: true,
          itemCount: itemCount(),
          itemBuilder: (c, i) {
            return pageBuild(c, i);
          })),
    );
  }

  itemCount();

  /// 子页面
  pageBuild(BuildContext context, int index);

  /// 底部的item
  barItems();
}
